using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Web;

namespace WorkflowManagement.Workflow.Activities
{
    [ActivityValidator(typeof(ResponseRedirectActivityValidator))]
    [ToolboxItem(typeof(ResponseRedirectActivityToolboxItem))]
    [Designer(typeof(WorkflowManagerActivityDesigner))]
	public partial class ResponseRedirectActivity: SequenceActivity
	{
        public ResponseRedirectActivity()
        {
            InitializeComponent();
        }

        public static DependencyProperty TargetUrlProperty = DependencyProperty.Register("TargetUrl", typeof(string), typeof(ResponseRedirectActivity));

        /// <summary>
        /// The url to redirect to.
        /// </summary>
        [Description("The target url to which the response is redirected.")]
        [Category("Target")]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string TargetUrl
        {
            get { return (string)base.GetValue(TargetUrlProperty); }
            set { base.SetValue(TargetUrlProperty, value); }
        }

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                HttpContext.Current.Response.Redirect(TargetUrl);
                return ActivityExecutionStatus.Closed;
            }
            catch
            {
                return ActivityExecutionStatus.Faulting;
            }            
        }

        private void PerformRedirect_ExecuteCode(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Redirect(TargetUrl);
        }
	
	}
}
